<?php
namespace Home\Controller;
use Home\Model\SetcardModel;
use Think\Controller;


class IndexController extends BaseController {

    public function index1(){
        self::index();
    }

    public function index(){
        $this->assign('title','设备状态');
        $this->assign('currentname','index');

        $Setcardinfo=new SetcardModel();
        $Setcardinfodata=$Setcardinfo->getSetcard();
        if($Setcardinfodata==false){

        }
        else{
            $_SESSION['cardinfo'] = $Setcardinfodata;

            $setcardstatus= [];

            for($i=0; $i < 4; $i++){
                $retdata = http_post_json($Setcardinfodata[$i]['cardip'] . C('LUCI_STATUS_URL') . 'getStatInfo', null);
                $js=(json_decode($retdata, true));
                $setcardstatus[$i]=$js[0][0];
            }

            $this->assign('setcardstatus', $setcardstatus);

            $this->assign('setcard', $Setcardinfodata);

            //获取gps数据，调用接口
        }
        if(session('wzwifi')){
            $this->assign('wzwifistatus', session('wzwifi'));
        }

        if(session('miguan')){
            $this->assign('miguanstatus', session('miguan'));
        }

        if(session('qxdyazhi')){
            $this->assign('qxdyazhistatus', session('qxdyazhi'));
        }


        $this->display();
    }

    public function APCamouflageAct(){
        if(IS_POST){
            if(I('post.action')=='start'){
                //先关闭
                session('wzwifi', null);
                $url=$_SESSION['cardinfo'][self::$cardtype_wz]['cardip'] .
                    C('LUCI_WIFISCAN_URL') . 'WZWifi/stop////';
                $retdata = http_post_json($url, null);
                sleep(1);
                $url=$_SESSION['cardinfo'][self::$cardtype_wz]['cardip'] . C('LUCI_WIFISCAN_URL') . 'WifiBypass/stop'
                    .'/'.''
                    .'/'.''
                    .'/'.''
                    .'/'.'';
                $ret = http_post_json($url, null);
                sleep(1);

                $filename = '/crackpath/ssid/fakeap.txt';
                file_put_contents($filename, I('post.ssid'));

                session('miguan','start');
                $url=$_SESSION['cardinfo'][self::$cardtype_package]['cardip'] .  C('LUCI_WIFISCAN_URL') . 'APCamouflageAct/' . I('post.action');

                $retdata = http_post_json($url, null);
                $js=(json_decode($retdata, true));

                $this->ajaxReturn(array('status'=>$js[0]), 'JSON');
            }
            else{
                session('miguan',null);

                $url=$_SESSION['cardinfo'][self::$cardtype_package]['cardip'] .  C('LUCI_WIFISCAN_URL') . 'APCamouflageAct/' . I('post.action');

                $retdata = http_post_json($url, null);
                $js=(json_decode($retdata, true));

                $this->ajaxReturn(array('status'=>$js[0]), 'JSON');
            }

        }
    }

    public function getgps(){
        if(IS_POST){
            $url=$_SESSION['cardinfo'][self::$cardtype_scan]['cardip'] .  C('LUCI_WIFISCAN_URL') . 'GetGPS/';

            $retdata = http_post_json($url, null);
            $js=(json_decode($retdata, true));

            $this->ajaxReturn(array('gps'=>$js[0]), 'JSON');
        }
    }

}